package com.zhangsheng.sentinel.block;

import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.zhangsheng.api.CommonResult;
import com.zhangsheng.api.ResultCode;
import com.zhangsheng.entity.model.Order;
import com.zhangsheng.entity.model.Product;
import com.zhangsheng.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * @author 张晟
 * @version 1.0
 * @date 2023/2/22 12:54
 */
@Slf4j
public class MysqlServiceBlock {

    public static CommonResult<Order> getOrderByIdBlock(Integer orderId, BlockException e) {
        log.error("访问资源getOrderById被限流，orderId={}", orderId);
        throw new BusinessException(ResultCode.FAILED.getCode(), "访问资源getOrderById被限流");
    }
    public static CommonResult<Order> createOrderBlock(Order order, BlockException e) {
        log.error("访问资源createOrder被限流，order={}", order);
        throw new BusinessException(ResultCode.FAILED.getCode(), "访问资源createOrder被限流");
    }

    public static CommonResult<Product> masterAddBlock(Product product, BlockException e) {
        log.error("访问资源masterAdd被限流，product={}", product);
        throw new BusinessException(ResultCode.FAILED.getCode(), "访问资源masterAdd被限流");
    }

    public static CommonResult<Product> getSlave1Block(Integer id, BlockException e) {
        log.error("访问资源getSlave1被限流，id={}", id);
        throw new BusinessException(ResultCode.FAILED.getCode(), "访问资源getSlave1被限流");
    }

    public static CommonResult<Product> getSlave2Block(Integer id, BlockException e) {
        log.error("访问资源getSlave2被限流，id={}", id);
        throw new BusinessException(ResultCode.FAILED.getCode(), "访问资源getSlave2被限流");
    }

    public static CommonResult<List<Order>> getOrderByPageBlock(Integer pageNum , Integer pageSize , BlockException e) {
        log.error("访问资源getOrderByPage被限流，pageNum={}，pageSize={}", pageNum, pageSize);
        throw new BusinessException(ResultCode.FAILED.getCode(), "访问资源getOrderByPage被限流");
    }

}
